Skip to content
This repository has been archived by the owner on Oct 22, 2019. It is now read-only.

WIP: Store if registry was initialized #67

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tback
Copy link

@tback tback commented Feb 22, 2018

This code is a work in progress. I'm opening the pull request this early to learn if you'd accept this when it's done?

Prometheus Authors (Brian) recommend to create zero value for metrics
known to exist in the future.

The usage pattern I want to enable is this:

$counter = $registry->registerCounter('namespace', 'metric', ['label_name']);
if(!$registry->initialized()){
    foreach($labelValues as $labelValue){
        $counter->incBy(0, [$labelValue]);
    }
}

Initialization is valid as for as long as the data exists in the storage
adapter.

Prometheus Authors (Brian) recommend to create zero value for metrics
known to exist in the future.

The usage pattern I want to enable is this:

$counter = $registry->registerCounter('namespace', 'metric', ['label_name']);
if(!$registry->initialized()){
    foreach($labelValues as $labelValue){
        $counter->incBy(0, [$labelValue]);
    }
}

Initialization is valid as for as long as the data exists in the storage
adapter.
@tback
Copy link
Author

tback commented Mar 13, 2018

It'd be great to know if this has a chance of getting accepted when it's done.

@bracki
Copy link
Contributor

bracki commented Mar 19, 2018

Would you mind adding a link to the post that describes the usage pattern you outlined above?

@bracki
Copy link
Contributor

bracki commented Mar 20, 2018

I read the blog post you mentioned. I would rather not add it. If you need to do it, it should be possible to do it on your own.
In the example from the blog post a Java static initializer is used, which makes sure the code only runs once. I don't think we should fix the shortcomings of PHP within this library. It's more of a pattern than a feature.

@tback
Copy link
Author

tback commented Mar 20, 2018

PHP doesn't provide a method to share data between requests out of the box. prometheus_client_php solves this shortcoming with storage adapters. Initializing metrics with 0 is a common usage pattern for prometheus and needs to share data between requests. Why is one inside the scope of this library, but the other one is not?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants